//
//  ACEConfirmOrderViewController.m
//  ACE
//
//  Created by zhangtao on 2018/8/14.
//  Copyright © 2018年 zt.td. All rights reserved.
//

#import "ACEConfirmOrderViewController.h"
#import "ACEStudyTableViewCell.h"
#import "ACEOrderInfoCell.h"
#import "ACEOrderPayCardCell.h"
#import "ACEOrderCouponCell.h"
#import "ACEConfirmBottomView.h"
#import "ACEMyPayWayViewController.h"
#import "ACECouponViewController.h"
@interface ACEConfirmOrderViewController ()<UITableViewDelegate,UITableViewDataSource>
#define orderIdentifier @"orderIdentifier"
#define infoIdentifier @"infoIdentifier"
#define cardIdentifier @"cardIdentifier"
#define couponIdentifier @"couponIdentifier"
@end

@implementation ACEConfirmOrderViewController
{
    UITableView *table;
    ACEConfirmBottomView *bottomView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"确认订单";
    [self createUI];
}

-(void)createUI{
    table = [[UITableView alloc]initWithFrame:CGRectMake(0, navHeight, ACEWidth, ACEHeight-navHeight-tabBarHeight) style:UITableViewStyleGrouped];
    table.backgroundColor = [UIColor whiteColor];
    table.delegate = self;
    table.dataSource = self;
    table.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:table];
    [table registerNib:[UINib nibWithNibName:@"ACEStudyTableViewCell" bundle:nil] forCellReuseIdentifier:orderIdentifier];
    [table registerNib:[UINib nibWithNibName:@"ACEOrderInfoCell" bundle:nil] forCellReuseIdentifier:infoIdentifier];
    [table registerNib:[UINib nibWithNibName:@"ACEOrderPayCardCell" bundle:nil] forCellReuseIdentifier:cardIdentifier];
    [table registerNib:[UINib nibWithNibName:@"ACEOrderCouponCell" bundle:nil] forCellReuseIdentifier:couponIdentifier];
    
    bottomView = [[ACEConfirmBottomView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(table.frame), ACEWidth, tabBarHeight)];
    [self.view addSubview:bottomView];
    bottomView.totalMoney = @"100";
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 4;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 10;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return .1;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [[UIView alloc]init];
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, table.frame.size.width, 10)];
    view.backgroundColor = [UIColor whiteColor];
    return view;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if( indexPath.section == 0)   return 110;
    if (indexPath.section == 1)   return 255;
    if(indexPath.section == 2)    return ACEWidth/3;
    if(indexPath.section == 3)        return 100;
    
    return 0;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        ACEStudyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:orderIdentifier];
        return cell;
    }else if (indexPath.section == 1){
        ACEOrderInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:infoIdentifier];
        return cell;
    }else if (indexPath.section == 2){
        ACEOrderPayCardCell *cell = [tableView dequeueReusableCellWithIdentifier:cardIdentifier];
        return cell;
    }else if (indexPath.section == 3){
        ACEOrderCouponCell *cell = [tableView dequeueReusableCellWithIdentifier:couponIdentifier];
        return cell;
    }
    
    UITableViewCell *cell = [UITableViewCell new];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 2) {
        ACEMyPayWayViewController *payway = [[ACEMyPayWayViewController alloc]init];
        [self.navigationController pushViewController:payway animated:YES];
    }
    
    if (indexPath.section == 3) {
        ACECouponViewController *coupon = [[ACECouponViewController alloc]init];
        [self.navigationController pushViewController:coupon animated:YES];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
